<?php

namespace App\Admin\Controllers;

use App\Models\User;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use Illuminate\Http\Request;

class DetailController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '明细查询';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $data = request()->all();
//        dd(111);
//        $where = [];
//        if(!empty($data['currency_type'])) {
//            $where['currency_type'] = $data['currency_type'];
//        }
//        if(!empty($data['type'])) {
//            $where['type'] = $data['type'];
//        }
//        $query = $this->user()->user_log()->where($where)->orderBy('id','desc');
//        if(!empty($data['starttime']) && !empty($data['endtime'])){
//            $query = $this->user()->user_log()->where($where)->where('created_at','>',$data['starttime'])->where('created_at','<',$data['endtime'])->orderBy('id','desc');
//        }
//        $res1 = $query->get();
//        $res['in'] = $query->sum('in');
//        $res['out'] = $query->sum('out');
//        $res['data'] = $res1;
        return view('detail');
    }

    public function search(Request $request){
        var_dump($request->type);
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(User::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('password', __('Password'));
        $show->field('remember_token', __('Remember token'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));
        $show->field('username', __('Username'));
        $show->field('mobile', __('Mobile'));
        $show->field('pid', __('Pid'));
        $show->field('balance', __('Balance'));
        $show->field('btc', __('Btc'));
        $show->field('electricity_fee', __('Electricity fee'));
        $show->field('push_num', __('Push num'));
        $show->field('team_num', __('Team num'));
        $show->field('is_real', __('Is real'));
        $show->field('real_name', __('Real name'));
        $show->field('id_number', __('Id number'));
        $show->field('bank_card', __('Bank card'));
        $show->field('btc_address', __('Btc address'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new User);

        //$form->password('password', __('密码'))->style('display:none')->default('123');
        $form->text('username', __('用户名'));
        $form->mobile('mobile', __('手机号'));
        $form->number('pid', __('上级用户'));
        $form->decimal('balance', __('余额'))->default(0.00000);
        $form->decimal('btc', __('比特币'))->default(0.0000000000);
        $form->decimal('electricity_fee', __('电费'))->default(0.00000);
        $form->number('push_num', __('直推数量'));
        $form->number('team_num', __('团队数量'));
        $form->number('is_real', __('是否直推'));
        $form->text('real_name', __('真实姓名'));
        $form->text('id_number', __('身份证号'));
        $form->text('bank_card', __('银行卡'));
        $form->text('btc_address', __('比特币地址'));
        $form->select('status', __('用户状态'))->options(config('conf.status'));;

        return $form;
    }
}
